package com.usian.article.article.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.article.article.fegin.ArticleLoadFegin;
import com.usian.article.article.mapper.ApCollectionBehaciorMapper;
import com.usian.model.article.ArticleInfoDto;
import com.usian.model.behavior.dto.ApUnlikesBehavior;
import com.usian.model.behavior.pojo.ApBehaviorEntry;
import com.usian.model.behavior.pojo.ApCollection;
import com.usian.model.behavior.pojo.ApFollowBehavior;
import com.usian.model.behavior.pojo.ApLikesBehavior;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.user.pojos.ApUser;
import com.usian.utils.threadlocal.AppThreadLocalUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/article/load/")
public class AploadController  {
    @Autowired
    private ArticleLoadFegin articleLoadFegin;

    @Autowired
    private ApCollectionBehaciorMapper apCollectionBehaciorMapper;

    @RequestMapping("load")
    public ResponseResult load(@RequestBody ArticleInfoDto dto){
        ApUser user = AppThreadLocalUtils.getUser();
        dto.setEntryId(user.getId());
        ApBehaviorEntry behaviorByid = articleLoadFegin.getBehaviorByid(dto);
        dto.setEntryId(behaviorByid.getId());
        boolean behavior=false;
        if(behaviorByid!=null){
            behavior=true;
        }

        ApFollowBehavior followByid = articleLoadFegin.getFollowByid(dto);
        boolean follow=false;
        if(followByid!=null){
            follow=true;
        }

        ApLikesBehavior likesByid = articleLoadFegin.getLikesByid(dto);
        boolean likes=false;
        if(likesByid!=null){
            likes=true;
        }

        ApUnlikesBehavior apUnlikesBehavior = articleLoadFegin.getunlikeByid(dto);
        boolean Unlikes=false;
        if(apUnlikesBehavior!=null){
            Unlikes=true;
        }

        ApCollection apCollection = apCollectionBehaciorMapper.selectOne(Wrappers.<ApCollection>lambdaQuery().
                eq(ApCollection::getEntryId, dto.getEntryId()).eq(ApCollection::getArticleId, dto.getArticleId()));
        boolean Collection=false;
        if(apCollection!=null){
            Collection=true;
        }

        return ResponseResult.okResult(null);
    }
}
